package com.example.administrator.dagger2demo.adapter.inter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.example.administrator.dagger2demo.R;
import com.example.administrator.dagger2demo.adapter.base.BaseRecyclerViewAdapter;
import com.example.administrator.dagger2demo.adapter.drag.ItemTouchHelperAdapter;
import com.example.administrator.dagger2demo.adapter.drag.OnStartDragListener;
import com.example.administrator.dagger2demo.utils.WindowUtil;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.Collections;
import java.util.List;

/**
 * 普通使用方式
 */
public class WorkAdapter extends BaseRecyclerViewAdapter<Indo, WorkAdapter.WorkViewHolder> implements ItemTouchHelperAdapter {
    protected final OnStartDragListener mDragStartListener;

    public WorkAdapter(List<Indo> list, OnStartDragListener mDragStartListener) {
        super(list);
        this.mDragStartListener = mDragStartListener;
    }


    @Override
    protected void bindDataToItemView(WorkViewHolder myViewHolder, Indo item) {
        int height = WindowUtil.getScreenHeight();
        int width = WindowUtil.getScreenWidth();
        SimpleDraweeView simpleDraweeView = (SimpleDraweeView) myViewHolder.getView(R.id.sdview);
        myViewHolder.setText(R.id.tv_show, item.getReleaseInfoUrl());
        simpleDraweeView.setLayoutParams(new FrameLayout.LayoutParams(width, height / 3));
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setUri("http://192.168.2.153:8080/MccServer" + item.getReleaseInfoUrl())
                .build();

        simpleDraweeView.setController(controller);
    }


    @Override
    public WorkViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) {

        return new WorkViewHolder(inflateItemView(viewGroup, R.layout.work_item));

    }


    public class WorkViewHolder extends BaseRecyclerViewAdapter.SparseArrayViewHolder {
        public WorkViewHolder(View itemView) {
            super(itemView);

        }

    }

    @Override
    public boolean onItemMove(int fromPosition, int toPosition) {
        Collections.swap(super.mList, fromPosition, toPosition);
        notifyItemMoved(fromPosition, toPosition);
        return true;
    }

    @Override
    public void onItemDismiss(int position) {
        super.mList.remove(position);
        notifyItemRemoved(position);
    }

}
